package com.jstyle.jclifexd.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.app.MyApplication;
import com.jstyle.jclifexd.model.Device181003;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/6/27.
 */

public class ExerciseModeAdapter extends RecyclerViewBaseAdapter<String> {


    public ExerciseModeAdapter(List<String> mDatas) {
        super(mDatas);
    }

    public void UPData() {
        notifyDataSetChanged();
    }
    Drawable drawable=null;
    @Override
    protected void bindData( BaseViewHolder holder, final int position) {
        Context context = holder.itemView.getContext();
        final ExerciseModeViewHolder exerciseModeViewHolder = (ExerciseModeViewHolder) holder;
        exerciseModeViewHolder.btExerciseMode.setText(mDataList.get(position));
        holder.itemView.setTag(position);
     switch (position){
         case 0:
             drawable=context.getResources().getDrawable(R.drawable.modebg_0);
             break;
         case 1:
             drawable=context.getResources().getDrawable(R.drawable.modebg_1);
             break;
         case 2:
             drawable=context.getResources().getDrawable(R.drawable.modebg_2);
             break;
         case 3:
             drawable=context.getResources().getDrawable(R.drawable.modebg_3);
             break;
         case 4:
             drawable=context.getResources().getDrawable(R.drawable.modebg_4);
             break;
         case 5:
             drawable=context.getResources().getDrawable(R.drawable.modebg_5);
             break;
         case 6:
             drawable=context.getResources().getDrawable(R.drawable.modebg_6);
             break;
         case 7:
             drawable=context.getResources().getDrawable(R.drawable.modebg_7);
             break;
         case 8:
             drawable=context.getResources().getDrawable(R.drawable.modebg_8);
             break;
         case 9:
             drawable=context.getResources().getDrawable(R.drawable.modebg_9);
             break;
         case 10:
             drawable=context.getResources().getDrawable(R.drawable.modebg_10);
             break;
     }

        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            exerciseModeViewHolder.btExerciseMode.setCompoundDrawables(null, drawable, null, null);
            exerciseModeViewHolder.btExerciseMode.setBackground(MyApplication.instance().getResources().getDrawable(R.drawable.ripple_bg));
        }
        ViewGroup.LayoutParams lp = exerciseModeViewHolder.btExerciseMode.getLayoutParams();
        if (hideYoga(position)) {
            lp.height = 0;
            lp.width = 0;
        } else {
            lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
            if (lp instanceof FlexboxLayoutManager.LayoutParams) {
                FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
                flexboxLp.setFlexBasisPercent(0.25f);
            }
        }



    }

    private boolean hideYoga(int position) {
        boolean show = false;
        if (5 == position) {
            if(MyApplication.getJstyleDevice() instanceof Device181003){
                show = true;
            }
        }
        return show;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = null;

        View viewOther = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false);
        baseViewHolder = new ExerciseModeViewHolder(viewOther);

        return baseViewHolder;
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_exercise_mode;
    }

    public class ExerciseModeViewHolder extends BaseViewHolder {

        @BindView(R.id.bt_exercise_mode)
        RadioButton btExerciseMode;

        public ExerciseModeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
